package com.tianji.promotion.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import lombok.Value;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;
import com.tianji.promotion.service.ICouponService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;


import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 控制器
 * </p>
 *
 * @author niu
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/coupons")
@Api(tags = "优惠券相关接口")
public class CouponController {

    private final ICouponService couponService;

    @ApiOperation("新增优惠券接口")
    @PostMapping
    public void saveCoupon(@RequestBody @Valid CouponFormDTO dto){
        couponService.saveCoupon(dto);
    }


    @GetMapping("/page")
    public PageDTO<CouponPageVO> page(CouponQuery query){
        return couponService.pageCoupon(query);
    }

    @PutMapping("/{id}/issue")
    public void issue(@PathVariable("id") Long id,@Valid  @RequestBody CouponIssueFormDTO dto){
        couponService.issue(id,dto);
    }

    @PutMapping("/{id}")
    public void updateCoupons(@PathVariable Long id ,@RequestBody @Valid CouponFormDTO dto){
        couponService.updateCoupons(id,dto);
    }
    @DeleteMapping("/{id}")
    public void deleteCoupons(@PathVariable Long id){
        couponService.deleteCoupons(id);
    }

    @GetMapping("/{id}")
    public CouponPageVO getCouponsById(@PathVariable Long id){
        return couponService.getCouponsById(id);
    }

    @PutMapping("/{id}/pause")
    public void updateCouponsStatus(@PathVariable Long id){
        couponService.updateCouponsStatus(id);
    }


    @GetMapping("/list")
    public List<CouponVO> couponList(){
        return couponService.couponList();
    }
}